package br.ufc.ck0017.ir.tree;


import br.ufc.ck0017.temp.Label;
import br.ufc.ck0017.temp.Temp;

import java.util.Arrays;
import java.util.List;

public class IR {
    public static final IRNode TRUE = CONST(1);
    public static final IRNode FALSE = CONST(0);

    public static final IRNode NOP = EXP(CONST(0));

    public static IRNode BINOP(BINOP.Operator op, IRNode l, IRNode r) {
        return new BINOP(op, l, r);
    }

    public static CALL CALL(Label lab, IRNode... args) {
        return new CALL(NAME(lab), Arrays.asList(args));
    }

    public static IRNode CALL(Label lab, List<IRNode> args) {
        return new CALL(NAME(lab), args);
    }

    public static IRNode CJUMP(CJUMP.LogicalOperator compare, IRNode l, IRNode r, Label t, Label f ) {
        return new CJUMP(compare, l, r, t, f);
    }

    public static IRNode CONST(int v) {
        return new CONST(v);
    }

    public static IRNode ESEQ(IRNode s, IRNode e) {
        if (s == NOP) {
            return e;
        }
        return new ESEQ(s,e);
    }

    public static IRNode EXP(IRNode exp) {
        return new EXP(exp);
    }

    public static LABEL LABEL(Label label) {
        return new LABEL(label);
    }

    public static MEM MEM(IRNode e) {
        return new MEM(e);
    }

    public static IRNode MOVE(IRNode d, IRNode s) {
        return new MOVE(d,s);
    }

    private static IRNode NAME(Label lab) {
        return new NAME(lab);
    }

    public static IRNode SEQ(IRNode l, IRNode r) {
        return new SEQ(l, r);
    }

    public static TEMP TEMP(Temp name) {
        return new TEMP(name);
    }

    public static JUMP JUMP(Label target) {
        return new JUMP(target);
    }
}